//
// A simple interface for monitoring changes
// happening to a store.
//

#ifndef LONGKEY_COMMON_STORE_WATCHER_H_
#define LONGKEY_COMMON_STORE_WATCHER_H_

#include "synchronized.h"

// Allows for monitoring changes happening to a store
// (independent of what the underlying store is).
class StoreWatcher
{
public:
	StoreWatcher() {}
	~StoreWatcher() {}

	// Called to create/reset the event that gets signaled
	// any time the store changes.  Access the created
	// event using change_event().
	virtual HRESULT EnsureEventSetup() = 0;

	// Indicates if any changes have occured
	bool HasChangeOccurred() const {
		return IsHandleSignaled(change_event());
	}

	// Get the event that is signaled on store changes.
	// Note:
	//   * This event will remain constant until the class is destroyed.
	//   * One should call EnsureEventSetup to set-up the event.
	//   * The event is only signaled on the next change and remains signaled.
	//     Do not call ::ResetEvent(). Call EnsureEventSetup() to reset
	//     the event and wait for more changes.
	virtual HANDLE change_event() const = 0;

private:
	DISALLOW_EVIL_CONSTRUCTORS(StoreWatcher);
};

#endif	// LONGKEY_COMMON_STORE_WATCHER_H_